package com.zzuli.yxypre.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.List;

/**
 * @auther pony
 * @create 2023-04-28 15:26
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Song implements Comparable<Song>{
    private Integer songId; //歌曲Id
    private String songName; //歌曲名字
    private String songLyric; //歌词
    private String songImg; //歌曲图片
    private String songUrl; //歌曲路径
    private Integer songStatus; //歌曲状态 0 正常 1 异常
    @DateTimeFormat(pattern="yyyy-MM-dd") //从前台接受的时间字符串格式，若格式不对应则抛出异常
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") //将Date日期格式化为指定格式的字符串
    private Date songTime; //歌曲上传时间

    //歌曲的歌手 不映射数据库
    @TableField(exist = false)
    private List<Singer> singer; //歌手
    //歌曲所属专辑 不映射数据库
    @TableField(exist = false)
    private List<Album> album; //专辑

    //是否被登录用户所喜欢 不映射数据库
    @TableField(exist = false)
    private Integer isLove; //喜欢 1:喜欢 2：不喜欢

    @TableField(exist = false)
    private Integer timeWeight; //时间权重

    @TableField(exist = false)
    private Integer playCountWeight; //播放量权重

    @TableField(exist = false)
    private Integer weekCount; //月播放量播放量

    @TableField(exist = false)
    private Double time; //处理后的时间

    @Override
    public int compareTo(Song song) {
        // 计算分数
        Double score1 = this.time * song.timeWeight + this.weekCount * song.playCountWeight;
        Double score2 = song.time * song.timeWeight + song.weekCount * song.playCountWeight;
        if (score1 > score2){
            return -1;
        }else {
            return 1;
        }
    }
}
